package com.charm.bulkcomponent.ui.activity

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter

import cn.bingoogolapple.bgabanner.BGABanner
import com.charm.bulkcomponent.R
import com.charm.codes.imageLoad.XGlide
import java.util.*


/**
 *
 * @author tools
 * @date 2017/7/13
 */
@Route(path = "/common/guide")
class GuideActivity : AppCompatActivity() {
    private lateinit var bannerGuide: BGABanner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_guide)
        initView()
        initEvent()
        initData()

    }


    /**
     *
     */
    private fun initView() {
        bannerGuide = findViewById(R.id.banner_guide_foreground)
    }

    /**
     *
     */
    private fun initData() {
        bannerGuide.setAdapter { _, itemView, model, _ ->
            XGlide.getInstance().with(this@GuideActivity)
                    .load(model as String)
                    .placeholder(com.charm.watercress.R.drawable.bg_block)
                    .error(com.charm.watercress.R.drawable.bg_block)
                    .into(itemView as ImageView)
                    .displayImage()
        }
        bannerGuide.setData(Arrays.asList("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2034093819,97968494&fm=27&gp=0.jpg",
                "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515567279&di=5fa91426d1fcc6389f8636dadd371306&imgtype=jpg&er=1&src=http%3A%2F%2Fs16.sinaimg.cn%2Fmiddle%2F77cb3463h79f1f7c3296f%26amp%3B690",
                "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514972592657&di=eacdaa9e524410edcadc25c74e87bb18&imgtype=0&src=http%3A%2F%2Fimg.25pp.com%2Fuploadfile%2Fbizhi%2Fiphone3%2F2013%2F0916%2F20130916040710971_thumb3.jpg"),
                Arrays.asList("", "", ""))
    }

    /**
     *
     */
    private fun initEvent() {
        /**
         * 设置进入按钮和跳过按钮控件资源 id 及其点击事件
         * 如果进入按钮和跳过按钮有一个不存在的话就传 0
         * 在 BGABanner 里已经帮开发者处理了防止重复点击事件
         * 在 BGABanner 里已经帮开发者处理了「跳过按钮」和「进入按钮」的显示与隐藏
         */
        bannerGuide.setEnterSkipViewIdAndDelegate(R.id.btn_guide_enter, R.id.tv_guide_skip) {
            ARouter.getInstance().build("/information/main/activity").navigation()
            finish()
        }
    }
}
